package com.suoluo.zenadmin.controllers.portal.trip;

import net.paoding.rose.web.ControllerInterceptorAdapter;
import net.paoding.rose.web.Invocation;

import com.suoluo.zenadmin.common.CommonResp;
import com.suoluo.zenadmin.common.config.SystemConfigHolder;
import com.suoluo.zenadmin.controllers.JSONInterceptor.JSON;
import com.suoluo.zenadmin.controllers.admin.AdminLoginManager;
import com.suoluo.zenadmin.vo.trip.UpdateTripStepRespVO;

public class TripInterceptor extends ControllerInterceptorAdapter{
	
	@Override
	protected Object before(Invocation inv) throws Exception {
		String remoteIP = inv.getRequest().getRemoteAddr();
		String publicIP = SystemConfigHolder.getTripPublicIP();
		if (publicIP.contains(remoteIP)){
			return true;
		}
		//验证是否后台登陆，否则返回登陆页面
		if (!AdminLoginManager.isLogined(inv)) {
             // 没有返回true或null，表示要中断整个处理流程，即不再继续调用其他拦截器以及最终的控制程
			 if (inv.isAnnotationPresent(JSON.class)){
				 //如果是JSON请求，需要返回未登录的状态码
				 String cpath = inv.getRequestPath().getCtxpath();
				 return new UpdateTripStepRespVO(CommonResp.ADMIN_NONLOGIN,"请重新登录",cpath+"/admin/login");
			 }else {
				 return "m:admin/login";
			 }
        }
		return true;
		
	}
}
